# Maintainer: lauren n. liberda <lauren@selfisekai.rocks>
pkgname=typst
pkgver=0.10.0
pkgrel=0
pkgdesc="New markup-based typesetting system that is powerful and easy to learn"
url="https://github.com/typst/typst"
# s390x: 90% of tests fail due to endianness
# armhf: fails build
# s390x, ppc64le, riscv64: ring
arch="all !s390x !ppc64le !riscv64 !armhf"
license="Apache-2.0"
makedepends="
	cargo
	cargo-auditable
	"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/typst/typst/archive/refs/tags/v$pkgver.tar.gz
	"
options="net"

prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

build() {
	# XXX: it vendors 5MB of fonts, but the font detection is kinda
	# broken and it won't find math symbols from system fonts correctly
	# (when you have a lot of fonts it seems?)
	# so, just keep them vendored-in for now. when fixed, add
	# --no-default-features
	GEN_ARTIFACTS="./gen" \
	TYPST_VERSION=$pkgver \
		cargo auditable build --release --frozen -p typst-cli
}

check() {
	cargo test --frozen --all
}

package() {
	install -Dm755 target/release/typst \
		-t "$pkgdir"/usr/bin/

	install -Dm644 ./crates/typst-cli/gen/typst.bash "$pkgdir"/usr/share/bash-completion/completions/typst
	install -Dm644 ./crates/typst-cli/gen/typst.fish "$pkgdir"/usr/share/fish/vendor_completions.d/typst.fish
	install -Dm644 ./crates/typst-cli/gen/_typst "$pkgdir"/usr/share/zsh/site-functions/_typst
	install -Dm644 ./crates/typst-cli/gen/*.1 -t "$pkgdir"/usr/share/man/man1/
}

sha512sums="
8203ed0157c0df580e954e5ed6dd97e4bfb30c8018f0fd3c52a8c1d959c383ed394bdc1957d9812fa4fb97c95c2670e87b9afe2e87c493c529b6aa54064aefa1  typst-0.10.0.tar.gz
"
